package io.renren.modules.shop.controller;


import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.shop.entity.ShopBrandEntity;
import io.renren.modules.shop.service.ShopBrandService;
import org.apache.commons.lang.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("/shop/brand")
public class ShopBrandController {


    @Autowired
    private ShopBrandService shopBrandService;

    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {

        //分页数据
        PageUtils pageUtils = shopBrandService.queryPage(params);

        return R.ok().put("page", pageUtils);
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable Long id) {

        //分页数据
        ShopBrandEntity brandEntity = shopBrandService.getById(id);

        return R.ok().put("brand", brandEntity);
    }



    @PostMapping("/save")
    public R save(@RequestBody ShopBrandEntity brandEntity) {

        ValidatorUtils.validateEntity(brandEntity);

        //分页数据
        shopBrandService.save(brandEntity);

        return R.ok();
    }

    @PostMapping("/update")
    public R update(@RequestBody ShopBrandEntity brandEntity) {

        ValidatorUtils.validateEntity(brandEntity);

        //分页数据
        shopBrandService.updateById(brandEntity);

        return R.ok();
    }


    @PostMapping("/delete")
    public R delete(@RequestBody Long[] userIds){

        shopBrandService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
